<?php
if( is_admin() ) {

	/* Start of: WordPress Administration */

	/* WordPress Administration Menu */
	function wpsc_fl_admin_menu() {

		add_options_page( __( 'Facebook Like Button for WP e-Commerce', 'wpsc_fl' ), __( 'Facebook Like Button', 'wpsc_fl' ), 'manage_options', 'wpsc_fl', 'wpsc_fl_html_page' );

	}
	add_action( 'admin_menu', 'wpsc_fl_admin_menu' );

	/* End of: WordPress Administration */

} else {

	/* Start of: Storefront */

	function wpsc_fl_init() {

		global $wp_query;

		$position = get_option( 'wpsc_fl_position' );
		$display_singleproduct = get_option( 'wpsc_fl_display_singleproduct' );
		$display_productspage = get_option( 'wpsc_fl_display_productspage' );

		if( $wp_query->is_single ) {
			if( $display_singleproduct ) {
				if( $position <> 'manual' )
					wpsc_fl_html_product();
			}
		} else {
			if( $display_productspage ) {
				if( $position <> 'manual' )
					wpsc_fl_html_product();
			}
		}

	}

	function wpsc_fl_html_product() {

		global $wp_query;

		$show_faces = get_option( 'wpsc_fl_show_faces' );
		switch( $show_faces ) {

			case '1':
				$show_faces = 'true';
				$height = 80;
				break;

			case '0':
				$show_faces = 'false';
				$height = 35;
				break;

		}
		$width = get_option( 'wpsc_fl_width' );
		$colour_scheme = get_option( 'wpsc_fl_colour_scheme' ); 
		$site = wpsc_clean_url( get_bloginfo() );

		if( $wp_query->is_single ) {
			$page = wpsc_clean_url( wpsc_this_page_url() );
			$title = wpsc_clean_url( wpsc_the_product_title() );
		} else {
			$page = wpsc_clean_url( wpsc_the_product_permalink() );
			$title = wpsc_clean_url( wpsc_the_product_title() );
		}
		if( is_ssl() )
			$page = str_replace( 'http', 'https', $page );

		$output = '<iframe src="http://www.facebook.com/plugins/like.php?href=' . $page . '&amp;layout=standard&amp;show_faces=' . $show_faces . '&amp;width=' . $width . '&amp;action=like&amp;font&amp;colorscheme=' . $colour_scheme . '&amp;height=' . $height . '&amp;title=' . $title . '&amp;site_name=' . $site . '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:' . $width . 'px; height:' . $height . 'px;" allowTransparency="true"></iframe>';
		echo $output;

	}

	/* End of: Storefront */

}
?>
